- Static display
- good for publication
- effective to show very specific pattern
- Interactive display
- gives end user more flexibility
- exploratory visualization is convenient
Feb 14, 2018
R packages for this lectureinstall.packages(c("ggplot2","plotly", "DT", "ggmap", "gapminder"))
gapminder packagelibrary(gapminder) dat <- subset(gapminder, year==2007)
library(ggplot2) p <- ggplot(dat, aes(x = log(gdpPercap), y = lifeExp))+ geom_point(aes(size = sqrt(pop/pi)), pch = 21, show.legend = FALSE) + scale_size_continuous(range=c(1,30)) + aes(fill = continent) p
library(plotly) ggplotly(p + aes(label = country))
q <- ggplot(gapminder, aes(x = log(gdpPercap), y = lifeExp, frame=year))+ geom_point(aes(size = sqrt(pop/pi)), pch = 21, show.legend = FALSE) + scale_size_continuous(range=c(1,30)) + aes(fill = continent) ggplotly(q)
library(DT) datatable(dat)
plot_ly(gapminder, x = ~gdpPercap, y = ~lifeExp, z = ~continent) %>% add_markers(color = ~continent)
library(ggmap)
crimes <- read.csv("omaha-crimes.csv")
omaps <- get_map(location = 'Omaha', maptype = 'roadmap', zoom = 11, color='bw')
p <- ggmap(omaps) +
geom_point(size=5, alpha = 1/2, aes(lon,lat, color=type), data = crimes)
ggplotly(p)
myMap <- get_map(maptype = "satellite", zoom = 8)
p <- ggmap(myMap) +
geom_polygon(aes(x = lon, y = lat, group = plotOrder),
data = zips, colour = "black", fill = NA)
ggplotly(p)